package com.ks.community.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ks.community.entity.Ingredient;
import com.ks.community.entity.vo.IngredientVo;
import com.ks.community.mapper.IngredientMapper;
import com.ks.community.service.IngredientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dCoder
 * @since 2022-04-04
 */
@Service
public class IngredientServiceImpl extends ServiceImpl<IngredientMapper, Ingredient> implements IngredientService {


    @Override
    public void addIngredient(IngredientVo ingredientVo) {
        Ingredient ingredient = new Ingredient();
        BeanUtils.copyProperties(ingredientVo,ingredient);
        baseMapper.insert(ingredient);
    }


    @Override
    public String selectByName(String name) {
        QueryWrapper<Ingredient> wrapper = new QueryWrapper<>();
        wrapper
                .eq("ingredient_name",name);
        String IngredientId = baseMapper.selectOne(wrapper).getIngredientId();
        return IngredientId;
    }

}
